home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / isbinary.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.3 KB  |  69 lines

  1. <!--- This example shows the use of ToBinary, IsBinary and ToBase64 --->
  2. <html>
  3. <head>
  4. <title>
  5. IsBinary Example
  6. </title>
  7. </head>
  8.  
  9. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  10. <BODY  bgcolor="#FFFFD5">
  11.  
  12. <h3>IsBinary Example</h3>
  13.  
  14. <!----------------------------------------------------------------------
  15. Initialize data.
  16. ----------------------------------------------------------------------->
  17. <CFSet charData ="">
  18. <!----------------------------------------------------------------------
  19. Create a string of all ASCII characters (32-255) and concatenate them together.
  20. ----------------------------------------------------------------------->
  21. <CFLoop index="data" from="32" to="255">
  22.     <CFSet ch=chr(data)>
  23.     <CFSet charData=charData & ch>
  24. </CFLoop>
  25. <p>
  26. The following string is the concatenation of all characters (32 to 255) from the ASCII table.<br>
  27. <cfoutput>#charData#</cfoutput>
  28. </p>
  29. <!----------------------------------------------------------------------
  30. Create a Base 64 representation of this string.
  31. ----------------------------------------------------------------------->
  32. <cfset data64=toBase64(charData)>
  33.  
  34. <!----------------------------------------------------------------------
  35. Convert string to binary.
  36. ----------------------------------------------------------------------->
  37. <CFSet binaryData=toBinary(data64)>
  38. <!----------------------------------------------------------------------
  39. Check to see if it really is a binary value.
  40. ----------------------------------------------------------------------->
  41.  
  42. <CFIf IsBinary(binaryData)>
  43.     <p>
  44.       It's binary alright!
  45.     </p>
  46. </CFif>
  47.  
  48. <!----------------------------------------------------------------------
  49. Convert binary back to Base 64.
  50. ----------------------------------------------------------------------->
  51. <CFSet another64=toBase64(binaryData)>
  52.  
  53. <CFIf Not IsBinary(another64)>
  54.     <p>
  55.       It's NOT binary now!
  56.     </p>
  57. </CFif>
  58. <!----------------------------------------------------------------------
  59. Compare another64 with data64 to ensure that they are equal.
  60. ----------------------------------------------------------------------->
  61. <CFIf another64 eq data64>
  62.     <h3>Base 64 representation of binary data is identical to the Base 64 
  63.     representation of string data.</h3>
  64. <CFElse>
  65.     <h3>Conversion error.</h3>
  66. </CFIf>
  67. </body>
  68. </html>
  69.